package com.emos.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;

public class R extends HashMap<String,Object> {

    public R(){
        put("code", HttpStatus.SC_OK);
        put("message","success");
    }

    /**
     * 可以链式调用
     * @param key
     * @param data
     * @return
     */
    public R put(String key,Object data){
        super.put(key,data);
        return this;
    }


    public static R ok(){
        return new R();
    }

    public static R ok(String msg){
        R r=new R();
        r.put("msg",msg);
        return r;
    }

    public static R error(){
        R r=new R();
        r.put("code",HttpStatus.SC_INTERNAL_SERVER_ERROR);
        r.put("msg","服务端异常");
        return r;
    }


}
